package networks.event;

import java.lang.reflect.Method;

public class Event {

    private Object _object; // 要执行方法的对象
    private String _methodName; // 要执行的方法名称
    private Class<?>[] _paramTypes; // 要执行方法的参数类型

    public Event(Object object, String method, Class<?>... paramTypes) {
        _object = object;
        _methodName = method;
        _paramTypes = new Class[paramTypes.length];
        for (int i = 0; i < paramTypes.length; i++) {
            _paramTypes[i] = paramTypes[i];
        }
    }

    public void Invoke(EventData eventData) {
        try {
            Method method = _object.getClass().getMethod(_methodName, _paramTypes); // 判断是否存在这个函数
            if (method == null) {
                return;
            }
            method.invoke(_object, eventData);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
}
